package com.exam.controller;


import com.exam.entity.JudgmentQuestions;
import com.exam.entity.common.ResponseResult;
import com.exam.service.JudgmentQService;
import com.exam.util.JsonUtils;
import com.exam.util.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class JudgmentQController {

    @Autowired
    @Qualifier("judgmentQServiceImpl")
    private JudgmentQService judgmentQService;
    ResponseResult responseResult=new ResponseResult();

    @RequestMapping("/add_judgment_question")
    @ResponseBody
    public String add_judgment_question(JudgmentQuestions judgmentQuestions){
        judgmentQuestions.setJ_creat_time(TimeUtils.getTime());
        int i = judgmentQService.add_judgment_question(judgmentQuestions);
        if (i==1){
            responseResult.setCode(200);
            responseResult.setMessage("添加成功");
        }else {
            responseResult.setCode(0);
            responseResult.setMessage("添加失败");
        }
        return JsonUtils.getJson(responseResult);
    }

    @RequestMapping("/get_judgmentQ_by_s_id")
    @ResponseBody
    public String get_judgmentQ_by_s_id(int s_id){
        List<JudgmentQuestions> judgmentQBySId = judgmentQService.get_judgmentQ_by_s_id(s_id);
        responseResult.setCode(0);
        responseResult.setMessage("成功");
        responseResult.setResult(judgmentQBySId);
        return JsonUtils.getJson(responseResult);
    }

    @RequestMapping("/update_judgmentQ_by_j_id")
    @ResponseBody
    public String update_judgmentQ_by_j_id(JudgmentQuestions judgmentQuestions){
        int i = judgmentQService.update_judgmentQ_by_j_id(judgmentQuestions);
        if (i==1){
            responseResult.setCode(200);
            responseResult.setMessage("修改成功");
        }else {
            responseResult.setCode(0);
            responseResult.setMessage("修改失败");
        }
        return JsonUtils.getJson(responseResult);
    }

    @RequestMapping("/del_judgmentQ_by_j_id")
    @ResponseBody
    public String del_judgmentQ_by_j_id(int j_id){
        int i = judgmentQService.del_judgmentQ_by_j_id(j_id);
        if (i==1){
            responseResult.setCode(200);
            responseResult.setMessage("删除成功");
        }else {
            responseResult.setCode(0);
            responseResult.setMessage("删除失败");
        }
        return JsonUtils.getJson(responseResult);
    }


    @RequestMapping("/get_jq_test_by_s_id")
    @ResponseBody
    public String get_jq_test_by_s_id(int s_id){
        List<JudgmentQuestions> jqTestBySId = judgmentQService.get_jq_test_by_s_id(s_id);
        responseResult.setCode(200);
        responseResult.setMessage("成功");
        responseResult.setResult(jqTestBySId);
        return JsonUtils.getJson(responseResult);
    }

}
